<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
<!--    <link rel="stylesheet" href="/layui/layui.js" media="all">-->
    <link rel="stylesheet" href="/css/custom.form.css">
    <link rel="stylesheet" href="/css/build.css?v=1">
    <script src="/js/jquery.js"></script>
    <!--    <script src="../../static/layui/layui.js"></script>-->
    <!--    <link rel="stylesheet" href="..css/layui/layui.css">-->
</head>
<style>
    .Impact{
        background-color: #6a79d6;
    }
</style>
<body>
<!--表单-->
<!--<script src="/layui/layui.all.js"></script>-->
<script src="/layui/layui.js"></script>
<script src="/js/core.util.js"></script>
<div class="layui-container" id="app">
    <div class="layui-fluid">
        <div class="panel panel-default operation_dept " hidden>
            <div class="panel-heading title"></div>
            <fieldset class="layui-elem-field layui-field-title  " style="margin-top: 25px;">

                <legend style="font-size: 25px;">
                    化验体检表
                </legend>
                <div class="layui-row">
                    <div class="layui-col-md6">
                        <legend style="font-size: 17px;font-weight: bolder;font-family: 华文宋体">
                            <div align="center">
                                编号：
                                <nobr id="ii"></nobr>
                            </div>
                        </legend>
                    </div>
                    <div class="layui-col-md6">
                        <legend style="font-size: 17px;font-weight: bolder;font-family: 华文宋体">
                            <div align="center">
                                姓名：
                                <nobr id="bb"></nobr>
                            </div>
                        </legend>
                    </div>
                </div>
            </fieldset>
            <form class="layui-form layui-form-pane layui-col-md3 " action="" lay-filter="deptInfo"
                  style="width: 900px;margin-top: 10px;position: center">
                <div class="layui-form-item ">
                    <label class="layui-form-label ">化验检查</label>
                    <div class="layui-input-block">
                        <!--                         style="  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">-->
                        <input id="Assay_test" type="text" name="length" lay-verify="title"
                               autocomplete="off" placeholder="请输入化验检查" class="layui-input WithUnit">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">医师意见</label>
                    <div class="layui-input-block">
                        <input id="Assay_idea" type="text" name="weight" lay-verify="title"
                               autocomplete="off" placeholder="请输入医师意见" class="layui-input WithUnit">
                    </div>
                </div>
                <!--                <div class="layui-form-item">-->
                <!--                    <label class="layui-form-label">检查医生id</label>-->
                <!--                    <div class="layui-input-block">-->
                <!--                        <input id="Assay_doctor_id" type="text" name="circle"-->
                <!--                               lay-verify="title" autocomplete="off" placeholder="请输入检查医生id"-->
                <!--                               class="layui-input WithUnit">-->
                <!--                    </div>-->
                <!--                </div>-->

                <div class="layui-form-item" align="center">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn Impact" lay-submit="" lay-filter="save">保存
                        </button>
                        <button class="layui-btn layui-btn-primary" id="btn_cancel" onclick="cancel()">返回</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!--搜索-->
<div class="demoTable">
    <div class="layui-form-item">
        <!--        搜索ID：-->

        <div class="layui-input-inline">
            <input class="layui-input" type="number" name="id" placeholder="请输入学生id" id="demoReload" autocomplete="off">
        </div>
        <div class="layui-input-inline ">
            <button class="layui-btn Impact" data-type="reload" id="searchID">搜索</button>
        </div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend style="font-size: 20px;">化验科体检</legend>
        </fieldset>
    </div>
    <table class="layui-hide" id="useruv" lay-filter="useruv"></table>
</div>


<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<script type="text/html" id="barDemo">
    <!--    class="layui-btn layui-btn-xs"-->
    <!--    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>-->
    <a class="layui-btn layui-btn-xs Impact" lay-event="edit">录入体检信息</a>
    <!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>
<table id="demo" lay-filter="test"></table>



<script>
    var check = 0;//检查是否出现表单不规范
    var tabledata;//表格中的数据
    var token = CoreUtil.getData("access_token");//header的token
    layui.use('table', function () {
        var table = layui.table;
        var token = CoreUtil.getData("access_token");
        // var table = layui.table;
        //第一个实例
        table.render({
            elem: '#useruv'
            , height: 350
            , headers: {"authorization": token}
            , url: '/assay/getStuList' //数据接口
            // , page: true //开启分页

            , cols: [
                [ //表头
                    // {checkbox: true, fixed: true}
                    {field: 'Stu_id', title: '编号', width: 80, sort: true, fixed: true, align: 'center'}
                    , {field: 'Stu_name', title: '姓名', width: 80, align: 'center'}
                    , {field: 'Stu_card', title: '身份证', width: 150, sort: true, align: 'center'}
                    , {field: 'Stu_college', title: '学院', width: 100, align: 'center'}
                    , {field: 'Stu_major', title: '专业', width: 100, align: 'center'}
                    , {field: 'Stu_class', title: '班级', width: 100, sort: true, align: 'center'}
                    , {field: 'Stu_num', title: '学号', width: 100, sort: true, align: 'center'}
                    , {field: 'Stu_sex', title: '性别', width: 50, align: 'center'}
                    , {field: 'Stu_birth', title: '出生年月日', width: 120, sort: true, align: 'center'}
                    , {
                    field: 'Assay_all', title: '状态', width: 80, sort: true, templet: function (item) {
                        if (item.Assay_all === "1") {
                            return ' <button type="button" class="layui-btn layui-btn-xs layui-btn-radius layui-btn-normal">已填</button>';
                        }
                        if (item.Assay_all === "0") {
                            return '<button type="button" class="layui-btn layui-btn-xs layui-btn-radius  layui-btn-primary">未填</button>';
                        }
                        if (item.Assay_all === "2") {
                            return '<button type="button" class="layui-btn layui-btn-xs layui-btn-radius layui-btn-danger">驳回</button>';
                        }
                    }

                }
                    , {fixed: 'right', title: '操作', width: 140, toolbar: "#barDemo", align: 'center'}
                ]
            ]
            , id: 'testReload'
            // , page: true
            // , height: 400
        });
        var $ = layui.$, active = {
            reload: function () {

                var demoReload = $('#demoReload');

                table.reload('testReload', {
                    // page: {
                    //     // curr: 1 //重新从第 1 页开始
                    // }

                    where: {
                        Stu_id: demoReload.val()
                    }
                });
            }
        };
        //回车搜索
        var search = document.getElementById("demoReload");
        search.addEventListener("keyup", function (event) {
            event.preventDefault();
            if (event.keyCode === 13) {
                console.log("hello");
                document.getElementById("searchID").click();
            }
        });

        //监听表格复选框选择
        table.on('checkbox(useruv)', function (obj) {
            console.log(obj)
        });
        //监听工具条
        table.on('tool(useruv)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.Stu_id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    console.log(data);
                    $.ajax({
                        url: "UVServlet",
                        type: "POST",
                        data: {"uvid": data.id, "memthodname": "deleteuv", "aid": data.aid},
                        dataType: "json",
                        success: function (data) {

                            if (data.state == 1) {
                                obj.del();
                                layer.close(index);
                                layer.msg("删除成功", {icon: 6});
                            } else {
                                layer.msg("删除失败", {icon: 5});
                            }
                        }

                    });
                });
            } else if (obj.event === 'edit') {
                EidtUv(data, obj);

            }
        });

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //编辑功能
        function EidtUv(data, obj) {
            // var datd = obj.data;
            tabledata = data;
            $(".operation_dept").show();

            $(".demoTable").hide();

            $("#ii").html(data.Stu_id);
            $("#bb").html(data.Stu_name);
            $.ajax({
                url: "/assay/getAssayInfo",
                type: "POST",
                headers: {"authorization": token},
                data: {"Stu_id": data.Stu_id},
                dataType: "json",
                success: function (res) {

                    if (res.code = '0') {
                        // console.log("getAssayInfo:"+res.toString());
                        console.log(res.msg);
                        console.log(res.data);
                        var Assay_test = res.data[0].Assay_test;
                        var Assay_idea = res.data[0].Assay_idea;
                        // var Assay_doctor_id = res.data[0].Assay_doctor_id;
                        // $("#Assay_doctor_id").val(Assay_doctor_id);
                        $("#Assay_idea").val(Assay_idea);
                        $("#Assay_test").val(Assay_test);
                    } else
                        alert(res.msg);
                },
                error: function (data) {

                }

            });
        }


    });
    layui.use(['form', 'layer', 'element'], function () {
        var form = layui.form;
        var layer = layui.layer;
        form.on('submit(save)', function (data) {
            console.log("save事件被触发了")
            // data.field.Stu_id = $("#Stu_id").html();
            // data = data.field;
            $.ajax({
                url: '/assay/insertAssayInfo',
                method: 'post',
                headers: {"authorization": token},
                data: {
                    // "assayDoctorId": $("#Assay_doctor_id").val(),
                    "assayIdea": $("#Assay_idea").val(),
                    "assayTest": $("#Assay_test").val(),
                    "stuId": tabledata.Stu_id
                    // "assayAll":"1",
                    // "assayError":"0"
                },
                dataType: 'JSON',
                success: function (res) {
                    console.log("录入成功:" + res);
                    if (res.code == '0'&&check==0) {
                        layer.msg('录入成功', {time: 1000}, function () {
                            $(".operation_dept").hide();
                            $(".table_div").show();
                            location.reload();
                        });


                    } else{

                    }
                        // alert(res.msg);
                },
                error: function (data) {

                }
            });

            return false;
        });
    });

    <!--表单规范-->

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 1) {
                    check=1;
                    return '请填写完所有信息';
                }else{
                    check=0;
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });

        //表单赋值
        layui.$('#LAY-component-form-setval').on('click', function () {
            form.val('example', {
                "username": "贤心" // "name": "value"
                , "password": "123456"
                , "interest": 1
                , "like[write]": true //复选框选中状态
                , "close": true //开关状态
                , "sex": "女"
                , "desc": "我爱 layui"
            });
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
        });


    });

</script>
<!--表单提交-->
<script>

</script>
</body>

</html>